import Vue from "vue";
import Router from "vue-router";

const Home = () => import("../views/home/Home.vue");
const Category = () => import("../views/category/Category.vue");
const Cart = () => import("../views/cart/Cart.vue");
const Profile = () => import("../views/profile/Profile.vue");
const Detail=()=>import("../views/detail/Detail.vue")

// const originalPush = Router.prototype.push;
// Router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err);
// };

// const originalReplace = Router.prototype.replace;
// originalReplace.replace = function replace(location) {
//   return originalReplace.call(this, location).catch(err => err);
// };

//安装插件
Vue.use(Router);

//创建路由对象
const routes = [
  {
    path: "",
    redirect: "/home"
  },
  {
    path: "/home",
    name: "Home",
    component: Home
  },
  {
    path: "/category",
    component: Category
  },
  {
    path: "/cart",
    component: Cart
  },
  {
    path: "/me",
    component: Profile
  },
  {
    path: "/detail/:iid",
    component: Detail
  }
];

const router = new Router({
  routes,
  mode: "history",
});
export default router;
